Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.479 lượt xem;
- PunPlayerScores.cs
- UtilityScripts /
- Photon Unity Networking /
- Assets /
- project /
1 using System.Collections.Generic;
2 using UnityEngine;
3 using System.Collections;
4 using Hashtable = ExitGames.Client.Photon.Hashtable;
5
6
7 public class PunPlayerScores : MonoBehaviour
8 {
9 public const string PlayerScoreProp = "score";
10 }
11
12
13 static class ScoreExtensions
14 {
15 public static void SetScore(this PhotonPlayer player, int newScore)
16 {
17 Hashtable score = new Hashtable(); // using PUN's implementation of Hashtable
18 score[PunPlayerScores.PlayerScoreProp] = newScore;
19
20 player.SetCustomProperties(score); // this locally sets the score and will sync it in-game asap.
21 }
22
23 public static void AddScore(this PhotonPlayer player, int scoreToAddToCurrent)
24 {
25 int current = player.GetScore();
26 current = current + scoreToAddToCurrent;
27
28 Hashtable score = new Hashtable(); // using PUN's implementation of Hashtable
29 score[PunPlayerScores.PlayerScoreProp] = current;
30
31 player.SetCustomProperties(score); // this locally sets the score and will sync it in-game asap.
32 }
33
34 public static int GetScore(this PhotonPlayer player)
35 {
36 object teamId;
37 if (player.customProperties.TryGetValue(PunPlayerScores.PlayerScoreProp, out teamId))
38 {
39 return (int)teamId;
40 }
41
42 return 0;
43 }
44 }
2 using UnityEngine;
3 using System.Collections;
4 using Hashtable = ExitGames.Client.Photon.Hashtable;
5
6
7 public class PunPlayerScores : MonoBehaviour
8 {
9 public const string PlayerScoreProp = "score";
10 }
11
12
13 static class ScoreExtensions
14 {
15 public static void SetScore(this PhotonPlayer player, int newScore)
16 {
17 Hashtable score = new Hashtable(); // using PUN's implementation of Hashtable
18 score[PunPlayerScores.PlayerScoreProp] = newScore;
19
20 player.SetCustomProperties(score); // this locally sets the score and will sync it in-game asap.
21 }
22
23 public static void AddScore(this PhotonPlayer player, int scoreToAddToCurrent)
24 {
25 int current = player.GetScore();
26 current = current + scoreToAddToCurrent;
27
28 Hashtable score = new Hashtable(); // using PUN's implementation of Hashtable
29 score[PunPlayerScores.PlayerScoreProp] = current;
30
31 player.SetCustomProperties(score); // this locally sets the score and will sync it in-game asap.
32 }
33
34 public static int GetScore(this PhotonPlayer player)
35 {
36 object teamId;
37 if (player.customProperties.TryGetValue(PunPlayerScores.PlayerScoreProp, out teamId))
38 {
39 return (int)teamId;
40 }
41
42 return 0;
43 }
44 }
Hashtable score = new Hashtable(); using PUN's implementation of Hashtable
player.SetCustomProperties(score); this locally sets the score and will sync it in-game asap.
Hashtable score = new Hashtable(); using PUN's implementation of Hashtable
player.SetCustomProperties(score); this locally sets the score and will sync it in-game asap.